package com.tripspins.app;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.ListView;

import com.tripspins.app.adapter.AttachmentListAdapter;
import com.tripspins.app.bo.Attachment;
import com.tripspins.app.bo.Pin;
import com.facebook.Session;
import com.facebook.SessionState;
import com.facebook.UiLifecycleHelper;
import com.facebook.widget.FacebookDialog;

import java.util.ArrayList;

/**
 * Created by joaortk on 23/11/13.
 */
public class ListAttachmentsActivity extends Activity {

    private ArrayList<Attachment> attachments;
    private UiLifecycleHelper uiHelper;
    private Pin pin;
    private long idTrip;
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_list_attachments);

        uiHelper = new UiLifecycleHelper(this, callback);
        uiHelper.onCreate(savedInstanceState);


        ListView listAttachments = (ListView)findViewById(R.id.listAttachments);
        Intent myIntent = getIntent();
        try{
            pin = myIntent.getParcelableExtra("pin");
            idTrip = myIntent.getLongExtra("idTrip",0);

        }catch(Exception e){
            //Log.e("T&P",e.getMessage());
        }
        AttachmentListAdapter adapter = new AttachmentListAdapter(this, pin,  idTrip, uiHelper);
        listAttachments.setAdapter(adapter);
    }
    private Session.StatusCallback callback = new Session.StatusCallback() {
        @Override
        public void call(Session session, SessionState state, Exception exception) {
            onSessionStateChange(session, state, exception);
        }
    };

    private void onSessionStateChange(Session session, SessionState state, Exception exception) {

    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        uiHelper.onSaveInstanceState(outState);
    }
    @Override
    protected void onResume() {
        super.onResume();
        uiHelper.onResume();
    }
    @Override
    public void onPause() {
        super.onPause();
        uiHelper.onPause();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        uiHelper.onDestroy();
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        uiHelper.onActivityResult(requestCode, resultCode, data, new FacebookDialog.Callback() {
            @Override
            public void onError(FacebookDialog.PendingCall pendingCall, Exception error, Bundle data) {
                //Log.e("Activity", String.format("Error: %s", error.toString()));
            }

            @Override
            public void onComplete(FacebookDialog.PendingCall pendingCall, Bundle data) {
                //Log.i("Activity", "Success!");
            }
        });
    }


}